package com.sloth.service.impl;

import com.sloth.mapper.AddressMapper;
import com.sloth.pojo.Address;
import com.sloth.pojo.AddressExample;
import com.sloth.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lai
 * @time 2021/10/10 16:09
 */
@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public Integer getByCustomerIdAndAddressDetail(Integer customerId,String addressDetail) {

        AddressExample example = new AddressExample();
        example.createCriteria().andCustIdEqualTo(customerId).andDetailedAddressEqualTo(addressDetail);

        // 因为一个用户的所有收货地址中，详细地址 只会有一个相同的，所以得到的集合中也只有一条数据
        Address address = addressMapper.selectByExample(example).get(0);

        return address.getAddressId();
    }
}